package com.wechat.servlet.Utils;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

// String 转 Base64
public class Base64Encoder {

    public static String encode(String s) {
        byte[] bytes = new byte[0];
        try {
            bytes = s.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Base64.Encoder encoder = Base64.getEncoder();
        String encodeStr = encoder.encodeToString(bytes);
        System.out.println("转码: "+encodeStr);
        return encodeStr;
    }
}
